# encoding: utf-8

class Project < ActiveRecord::Base
  has_many  :bugs,
            :dependent  =>  :destroy

  has_many  :dataobjects,
            :dependent  =>  :destroy

  has_many  :topics,
            :dependent  =>  :destroy

  has_many  :workpackages,
            :dependent  =>  :destroy

  has_many  :members,
            :dependent  =>  :destroy

  has_many  :users,
            :through => :members

  # Validations

  validates :name,
            :presence   =>  true,
            :uniqueness =>  true,
            :length     =>  { :within =>  5..255 }

  validates :description,
            :length => {  :within      => 5..500 }

  validates :url,
            :length => {  :within       => 5..255}

  validates :status,
            :presence   =>  true,
            :inclusion  =>  { :in =>  ['initial', 'in_progress', 'delayed', 'finished', 'canceled'] }

  validates :progress,
            :presence     =>  true,
            :numericality =>  { :only_integer             =>  true,
                                :greater_than_or_equal_to =>  0,
                                :less_than_or_equal_to    =>  100 }

end

# == Schema Information
#
# Table name: projects
#
#  id          :integer         not null, primary key
#  name        :string(255)
#  description :text
#  url         :string(255)
#  status      :string(255)     default("initial")
#  progress    :integer         default(0)
#  created_at  :datetime
#  updated_at  :datetime
#

